﻿using AForge.Video.DirectShow;
using AForge.Controls;
using System.Collections.Generic;
using System.Net;
using System.IO;

namespace VCMW
{
    class Helper
    {
        /// <summary>
        /// AForge类库打开摄像头
        /// </summary>
        public void openCan(VideoSourcePlayer videoSourcePlayer1, VideoSourcePlayer.NewFrameHandler videoSourcePlayer1_NewFrame, FilterInfoCollection videoDevices)
        {
            //连接摄像头。
            VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[0];
            // 枚举所有摄像头支持的像素，设置拍照为1920*1080
            foreach (VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                {
                    videoSource.VideoResolution = capab;
                    break;
                }
                if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                {
                    videoSource.VideoResolution = capab;
                    break;
                }
            }
            videoSourcePlayer1.NewFrame += new VideoSourcePlayer.NewFrameHandler(videoSourcePlayer1_NewFrame);
            videoSourcePlayer1.VideoSource = videoSource;

            // set NewFrame event handler
            videoSourcePlayer1.Start();
        }

        //发送人脸识别 http 请求函数
        public string createHttp(string url, Dictionary<string, object> verifyPostParameters)
        {
            HttpWebResponse verifyResponse = HttpHelper4MultipartForm.MultipartFormDataPost(url, "", verifyPostParameters);
            Stream str = verifyResponse.GetResponseStream();
            StreamReader str1 = new StreamReader(str);
            string xx = str1.ReadToEnd();
            return xx;
        }

        /// <summary>
        /// 设置对应情绪词
        /// </summary>
        /// <param name="lab_qx_left_bottom"></param>
        /// <param name="lab_qx_left"></param>
        /// <param name="lab_qx_right"></param>
        /// <param name="str1"></param>
        /// <param name="str2"></param>
        /// <param name="str3"></param>
        public void faceFeature(System.Windows.Forms.Label aq_qingxu_lab, System.Windows.Forms.Label lab_qx_left_bottom, System.Windows.Forms.Label lab_qx_left, System.Windows.Forms.Label lab_qx_right, string str1, string str2, string str3, int str4)
        {
            aq_qingxu_lab.Text = str4.ToString();
            lab_qx_left_bottom.Text = str1;
            lab_qx_left.Text = str2;
            lab_qx_right.Text = str3;
        }

        
    }
}
